const router = require('koa-router')()

const Customer = require('../models/customer')

router.get('/', async (ctx, next) => {
    let language = ctx.request.query.language || 'en_us'
    await ctx.render('index_' + language)
})

router.post('/', async (ctx, next) => {
    try {
        let res = await Customer.create(ctx.request.body.customer)

        if(res) {
            ctx.body = { message: '提交成功'}
        } else {
            ctx.body = { message: '提交失败'}
        }
    } catch(e) {
        ctx.body = { message: '您提交的数据有误或邮箱重复'}
    }
})

module.exports = router
